package cn.shyouchi.wuguanjia.android.ui.meetting.feedback;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.api.meet.MeetApi;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.model.BaseRequestResult;
import cn.shyouchi.wuguanjia.android.subscribers.ProgressSubscriber;
import cn.shyouchi.wuguanjia.android.widget.TopBar;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class FeedbackMeetActivity extends BaseActivity {

    FeedbackAdapter mFeedbackAdapter;


    List<FeedbackEntity> mFeedbackEntities = new ArrayList<>();
    @BindView(R.id.topBar)
    TopBar mTopBar;
    @BindView(R.id.rv_applies)
    RecyclerView mRvApplies;

    MeetApi mMeetApi;

    @Override
    public int initContentView() {
        return R.layout.activity_feedbak_meet;
    }

    @Override
    public void initInjector() {
        mMeetApi = new MeetApi(mContext);
    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setTitle(getTitle().toString());
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(mTopBar.getToolbar());

        mFeedbackAdapter = new FeedbackAdapter(mFeedbackEntities);
        mRvApplies.setAdapter(mFeedbackAdapter);
        mRvApplies.setLayoutManager(new LinearLayoutManager(mContext));

        fetchList();

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }


    private void fetchList() {
        mMeetApi.fetchRoomList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber<BaseRequestResult<List<FeedbackEntity>>>(mContext) {
                    @Override
                    public void onNext(BaseRequestResult<List<FeedbackEntity>> listBaseRequestResult) {
                        mFeedbackEntities.clear();
                        mFeedbackEntities.addAll(listBaseRequestResult.getResultMessage());
                        mFeedbackAdapter.notifyDataSetChanged();
                    }
                });
    }

}
